package com.twang.stock.task.old;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.common.CommonUtils;
import com.twang.stock.common.HotTagCommon;
import com.twang.stock.entity.CompanyCodeInfo;
import com.twang.stock.entity.HotTag;
import com.twang.stock.mapper.CompanyCodeInfoMapper;
import com.twang.stock.service.CompanyStockMinutesService;
import com.twang.stock.service.jinyan.CompanyCodeInfoService;
import com.twang.stock.service.jinyan.HolidayService;
import com.twang.stock.service.jinyan.HotTagService;
import com.twang.stock.email.SendmailService;
import com.twang.stock.threadPool.AsycTaskExecutorConfig;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Component
public class 今日精选Task extends BaseTask {

    @Autowired
    private AsycTaskExecutorConfig asycTaskExecutorConfig;

    @Autowired
    private SendmailService sendmailService;

    @Resource
    private CompanyCodeInfoMapper companyCodeInfoMapper;

    @Autowired
    private HolidayService holidayService;

    @Autowired
    private HotTagService hotTagService;

    @Autowired
    private CompanyStockMinutesService companyStockMinutesService;
    @Autowired
    private CompanyCodeInfoService companyCodeInfoService;


   @Scheduled(cron = "0 30 01 * * ?")
    public void excute() {
        try {
            List<CompanyCodeInfo> stockList = companyCodeInfoMapper.getStockInfoMoreThan5(holidayService.getDayByNum(0));
            HotTag hotTag = hotTagService.createHotTagByName(HotTagCommon.getHotTagBynameAnddate(HotTagCommon.HOT_TAG_JINGXUAN, holidayService.getDayByNum(0)));
            for (CompanyCodeInfo item : stockList) {
                asycTaskExecutorConfig.taskQueueExecutor().execute(()->{
                    String code = item.getCompanyCode();
                    code = code.replace("name_", "").trim();
                    CompanyCodeInfo companyCodeInfo = companyCodeInfoService.getInfoByStockName(code);
                    //
                    List<String> days = Lists.newArrayList();
                    companyStockMinutesService.getMaxTradeMinutesVol(code, days);
                });
            }
        } catch (Exception e) {
            sendmailService.insertEvent(CommonUtils.TASK_NAME_RULE_6, CommonUtils.FAILE_MESSAGE + JSONObject.toJSONString(e), "ERROR", CommonUtils.RULE_EXCEPTION);
        }
    }

    /**
     *
     * @param item
     * @param hotTag
     */
    private void excuteRules(CompanyCodeInfo item,  HotTag hotTag) {
        if (null != item.getStrongRise() && null != item.getStrongRiseVol()) {
            if (item.getStrongRise().intValue() == 1 && item.getStrongRiseVol().intValue() == 1) {
                hotTagService.inserStockTagFor精选(hotTag.getId(), item.getId());
            }
        }
    }
}
